// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import "fmt"

func subsets(set []int) [][]int {
	n := len(set)
	power := 1 << uint(n)
	subsets := make([][]int, 0)

	for i := 0; i < power; i++ {
		subset := make([]int, 0)
		for j := 0; j < n; j++ {
			if i&(1<<uint(j)) != 0 {
				subset = append(subset, set[j])
			}
		}
		subsets = append(subsets, subset)
	}

	return subsets
}

func main() {
	set := []int{1, 6, 8}
	result := subsets(set)
	fmt.Println(result)
}

//$ go run interview10-11.go
//[[] [1] [6] [1 6] [8] [1 8] [6 8] [1 6 8]]
